using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
namespace Ramparts
{
     
    public class Scene
    {


        protected KeyboardState currentKeyboardState;
        protected MouseState currentMouseState;

        protected KeyboardState previousKeyboardState;
        protected MouseState previousMouseState;

        public Rectangle viewportRect;
      
        protected List<GameComponent> sceneComponents;
    
        public SceneManager sceneManager;
        
        protected Texture2D backgroundTexture;
        
        public Camera2D camera;
        
        public bool useCamera = true;

        public Scene(SceneManager sceneMgr)
        {
            sceneManager = sceneMgr;
        }

        public bool addComponentToScene(GameComponent inComponent){

            sceneComponents.Add(inComponent);
            return true;
        
        }

        public Scene()
        {
            sceneComponents = new List<GameComponent>();
        }

        virtual public void Update(GameTime gameTime)
        {
            camera.Update(gameTime);
            processMouseEvents(gameTime);
            processKeyboardEvents(gameTime);
        
        }

        virtual public bool initScene()
        {
           
            camera = new Camera2D(sceneManager.rampart, true);
            previousMouseState = Mouse.GetState();
            currentKeyboardState = Keyboard.GetState();
            camera.Initialize();
            return true;
        }


        protected virtual void processMouseEvents(GameTime gameTime)
        {
            currentMouseState = Mouse.GetState();
        }

        protected virtual void processKeyboardEvents(GameTime gameTime)
        {
            currentKeyboardState = Keyboard.GetState();
        }

        virtual public void drawScene()
        {
            
            if (useCamera)
            {
                sceneManager.rampart.spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState, camera.Transform);
            }
            else
            {
                // Do Nothing            
            }
            
            // Draw Game Componenets
            drawComponents();

        }

        public void drawComponents()
        {
            foreach (GameComponent component in sceneComponents)
            {
                component.Draw();
            }
        }
    }
}
